package com.ruoyi.cost.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Map;

/**
 * 科目余额及发生额对象 acc_amount
 * 
 * @author 王志旸
 * @date 2024-07-09
 */
@Data
public class AccAmount extends BaseEntity
{
//    private static final long serialVersionUID = 1L;

    /**  */
    private String id;

    public AccAmount() {
    }

    /** 科目编号 */
    @Excel(name = "科目编号")
    private String accSubNum;

    /** 期初余额方向 */
    @Excel(name = "期初余额方向")
    private String startBalance;

    /** 期末余额方向 */
    @Excel(name = "期末余额方向")
    private String endBalance;

    public AccAmount(String id, String accSubNum, String startBalance, String endBalance, String accYear, String accPeriod, String startNum, String startOriginalCurr, String startLocalCurr, String debtorNum, String debtorOriginalCurr, String debtorLocalCurr, String creditNum, String creditOriginalCurr, String creditLocalCurr, String endNum, String endOriginalCurr, String endLocalCurr, String spare1, String spare2, String spare3, String spare4, String spare5, String spare6, String spare7, String spare8, String spare9, String spare10, String spare11, String spare12, String spare13, String spare14, String spare15, String spare16, String spare17, String spare18, String spare19, String spare20, String spare21, String spare22, String spare23, String spare24, String spare25, String spare26, String spare27, String spare28, String spare29, String spare30, String accMode, String accSubName, String direction, String supMap) {
        this.id = id;
        this.accSubNum = accSubNum;
        this.startBalance = startBalance;
        this.endBalance = endBalance;
        this.accYear = accYear;
        this.accPeriod = accPeriod;
        this.startNum = startNum;
        this.startOriginalCurr = startOriginalCurr;
        this.startLocalCurr = startLocalCurr;
        this.debtorNum = debtorNum;
        this.debtorOriginalCurr = debtorOriginalCurr;
        this.debtorLocalCurr = debtorLocalCurr;
        this.creditNum = creditNum;
        this.creditOriginalCurr = creditOriginalCurr;
        this.creditLocalCurr = creditLocalCurr;
        this.endNum = endNum;
        this.endOriginalCurr = endOriginalCurr;
        this.endLocalCurr = endLocalCurr;
        this.spare1 = spare1;
        this.spare2 = spare2;
        this.spare3 = spare3;
        this.spare4 = spare4;
        this.spare5 = spare5;
        this.spare6 = spare6;
        this.spare7 = spare7;
        this.spare8 = spare8;
        this.spare9 = spare9;
        this.spare10 = spare10;
        this.spare11 = spare11;
        this.spare12 = spare12;
        this.spare13 = spare13;
        this.spare14 = spare14;
        this.spare15 = spare15;
        this.spare16 = spare16;
        this.spare17 = spare17;
        this.spare18 = spare18;
        this.spare19 = spare19;
        this.spare20 = spare20;
        this.spare21 = spare21;
        this.spare22 = spare22;
        this.spare23 = spare23;
        this.spare24 = spare24;
        this.spare25 = spare25;
        this.spare26 = spare26;
        this.spare27 = spare27;
        this.spare28 = spare28;
        this.spare29 = spare29;
        this.spare30 = spare30;
        this.accMode = accMode;
        this.accSubName = accSubName;
        this.direction = direction;
        this.supMap = supMap;
    }

    /** 会计年度 */
    @Excel(name = "会计年度")
    private String accYear;

    /** 会计期间号 */
    @Excel(name = "会计期间号")
    private String accPeriod;

    /** 期初数量 */
    @Excel(name = "期初数量")
    private String startNum;

    /** 期初原币金额 */
    @Excel(name = "期初原币金额")
    private String startOriginalCurr;

    /** 期初本币金额 */
    @Excel(name = "期初本币金额")
    private String startLocalCurr;

    /** 借方数量 */
    @Excel(name = "借方数量")
    private String debtorNum;

    /** 借方原币金额 */
    @Excel(name = "借方原币金额")
    private String debtorOriginalCurr;

    /** 借方本币金额 */
    @Excel(name = "借方本币金额")
    private String debtorLocalCurr;

    /** 贷方数量 */
    @Excel(name = "贷方数量")
    private String creditNum;

    /** 贷方原币金额 */
    @Excel(name = "贷方原币金额")
    private String creditOriginalCurr;

    /** 贷方本币金额 */
    @Excel(name = "贷方本币金额")
    private String creditLocalCurr;

    /** 期末数量 */
    @Excel(name = "期末数量")
    private String endNum;

    /** 期末原币金额 */
    @Excel(name = "期末原币金额")
    private String endOriginalCurr;

    /** 期末本币金额 */
    @Excel(name = "期末本币金额")
    private String endLocalCurr;


    /** 辅助项1编号 */
    @Excel(name = "辅助项1编号")
    private String spare1;

    /** 辅助项2编号 */
    @Excel(name = "辅助项2编号")
    private String spare2;

    /** 辅助项3编号 */
    @Excel(name = "辅助项3编号")
    private String spare3;

    /** 辅助项4编号 */
    @Excel(name = "辅助项4编号")
    private String spare4;

    /** 辅助项5编号 */
    @Excel(name = "辅助项5编号")
    private String spare5;

    /** 辅助项6编号 */
    @Excel(name = "辅助项6编号")
    private String spare6;

    /** 辅助项7编号 */
    @Excel(name = "辅助项7编号")
    private String spare7;

    /** 辅助项8编号 */
    @Excel(name = "辅助项8编号")
    private String spare8;

    /** 辅助项9编号 */
    @Excel(name = "辅助项9编号")
    private String spare9;

    /** 辅助项10编号 */
    @Excel(name = "辅助项10编号")
    private String spare10;

    /** 辅助项11编号 */
    @Excel(name = "辅助项11编号")
    private String spare11;

    /** 辅助项12编号 */
    @Excel(name = "辅助项12编号")
    private String spare12;

    /** 辅助项13编号 */
    @Excel(name = "辅助项13编号")
    private String spare13;

    /** 辅助项14编号 */
    @Excel(name = "辅助项14编号")
    private String spare14;

    /** 辅助项15编号 */
    @Excel(name = "辅助项15编号")
    private String spare15;

    /** 辅助项16编号 */
    @Excel(name = "辅助项16编号")
    private String spare16;

    /** 辅助项17编号 */
    @Excel(name = "辅助项17编号")
    private String spare17;

    /** 辅助项18编号 */
    @Excel(name = "辅助项18编号")
    private String spare18;

    /** 辅助项19编号 */
    @Excel(name = "辅助项19编号")
    private String spare19;

    /** 辅助项20编号 */
    @Excel(name = "辅助项20编号")
    private String spare20;

    /** 辅助项21编号 */
    @Excel(name = "辅助项21编号")
    private String spare21;

    /** 辅助项22编号 */
    @Excel(name = "辅助项22编号")
    private String spare22;

    /** 辅助项23编号 */
    @Excel(name = "辅助项23编号")
    private String spare23;

    /** 辅助项24编号 */
    @Excel(name = "辅助项24编号")
    private String spare24;

    /** 辅助项25编号 */
    @Excel(name = "辅助项25编号")
    private String spare25;

    /** 辅助项26编号 */
    @Excel(name = "辅助项26编号")
    private String spare26;

    /** 辅助项27编号 */
    @Excel(name = "辅助项27编号")
    private String spare27;

    /** 辅助项28编号 */
    @Excel(name = "辅助项28编号")
    private String spare28;

    /** 辅助项29编号 */
    @Excel(name = "辅助项29编号")
    private String spare29;

    /** 辅助项30编号 */
    @Excel(name = "辅助项30编号")
    private String spare30;


    @Excel(name = "账套")
    private String accMode;

    @TableField(exist = false)
    private String accSubName;
    @TableField(exist = false)
    private String direction;

    private String supMap;

    public void add(AccAmount other) {
        this.creditLocalCurr = sumWithPrecision(this.creditLocalCurr, other.creditLocalCurr);
        this.debtorLocalCurr = sumWithPrecision(this.debtorLocalCurr, other.debtorLocalCurr);
        this.startLocalCurr = sumWithPrecision(this.startLocalCurr, other.startLocalCurr);
        this.endLocalCurr = sumWithPrecision(this.endLocalCurr, other.endLocalCurr);
    }

    // 工具方法：将两个字符串表示的数字相加，并保留两位小数
    private String sumWithPrecision(String a, String b) {
        BigDecimal num1 = new BigDecimal(a);
        BigDecimal num2 = new BigDecimal(b);
        BigDecimal sum = num1.add(num2);
        return sum.setScale(2, BigDecimal.ROUND_HALF_UP).toString(); // 保留两位小数，四舍五入
    }
}
